<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%"
    >
      <el-table-column
        prop="id"
        label="编号"
        width="80">
      </el-table-column>
      <el-table-column
        prop="name"
        label="名称"
        width="100">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="180">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="220">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="时间"
        width="120">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="300">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      align="right"
      background
      layout="prev, pager, next"
      :current-page="currentPage"
      :total="total"
      :page-size="pageSize"
      @current-change="currentPageChange">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'Department',
  /**/
  data () {
    return {
      tableData:[],
      total:0,
      pageSize:10,
      currentPage:4
    }
  },
  methods:{
    currentPageChange(currentPage){
      //如果调用此方法 说明点了分页的页码
      this.currentPage = currentPage;
      //重新加载数据
      this.getDepartments();
    },
    getDepartments(currentPage){
      /*if(currentPage){
        this.currentPage = currentPage
      }*/
      alert(this.currentPage);
      this.$http.post("/dept/list",{"currentPage":this.currentPage})
        .then(result=>{//后台响应数据
          result = result.data;
          console.log(result);
          this.tableData  = result.rows;
          this.total  = result.total;
        })
        .catch(result=>{
          console.log(result);
          alert("系统错误");
        })
    }
  },
  mounted(){
    this.getDepartments();
  }
}
</script>
<style scoped>
</style>
